package com.woniu.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.pojo.House;
import com.woniu.pojo.Proposer;
import com.woniu.pojo.Registerbook;
import com.woniu.pojo.User;
import com.woniu.service.HouseService;
import com.woniu.service.ProposerService;
import com.woniu.service.RegisterBookService;
import com.woniu.service.UserService;

@RestController
@RequestMapping("rbc")
public class RegisterbookController {

	@Autowired
	private RegisterBookService registerBookService;
	@Autowired
	private UserService userService;
	@Autowired
	private ProposerService proposerService;
	@Autowired
	private HouseService houseService;
	
	 @RequestMapping("list")
	 
	    public PageInfo getAll(String user_name,String registerBook_id,String pp_id,@RequestParam(required = false,defaultValue = "1",value = "pageNum")Integer pageNum, Map<String,Object> map){
	            //System.out.println("��ҳ��ʾ");
	           System.out.println("---1---");
	            //���÷�ҳ����
		 
	            PageHelper.startPage(pageNum,7);
	            //��ѯȫ���б�
	           // String condition[]= {u_id,registerBook_id,pp_id};
	            
	            List<Registerbook>  list=registerBookService.getAllRegisterBookByCondition(user_name,registerBook_id,pp_id);
	           // List<Registerbook>  list=registerBookService.getAllRegisterBook();

	            //System.out.println("11111111111111111"+list);
	            PageInfo pageInfos=new PageInfo(list);
	            System.out.println(pageInfos);
	            map.put("pageInfos",pageInfos);
	           // System.out.println(pageInfos);
	            return pageInfos;
	        }
	@RequestMapping("addRegisterbook")
	public String addRegisterbook(Registerbook registerbook) {
		registerBookService.addRegisterbook(registerbook);
		return "添加成功";
	}
	@RequestMapping("deleteRegisterbookById")
	public String deleteRegisterbookById(Integer rb_id) {
		registerBookService.deleteRegisterbookById(rb_id);
		return "删除成功";
	}
	@RequestMapping("deleteRegisterbooksById")
	public String deleteRegisterbooksById(String rb_ids) {
		registerBookService.deleteRegisterbooksById(rb_ids);
		return "删除"+rb_ids+"成功";
	}
	@RequestMapping("getUpdateRegisterBookInfo")
	public Registerbook getUpdateRegisterBookInfo(Integer rb_id) {
		
		Registerbook registerbook=registerBookService.getUpdateRegisterBookInfo(rb_id);
		
		return registerbook;
	}
	@RequestMapping("getPPByppid")
	public Proposer getPPByppid(Integer pp_id) {
		//System.out.println("======="+pp_id);
		Proposer proposer=proposerService.getProposerByid(pp_id);
		//System.out.println(proposer);
		return proposer;
	}
	@RequestMapping("getHouseByh_id")
	public House getHouseByh_id(Integer pp_id) {
		//System.out.println("======="+pp_id);
		Proposer proposer=getPPByppid(pp_id);
		System.out.println(proposer);
		House house=houseService.getHouseById(proposer.getH_id());
		return house;
	}
	@RequestMapping("updateRegisterBook")
	public String updateRegisterBook(Registerbook registerbook) {
		
		registerBookService.updateRegisterBook(registerbook);
		
		return "修改成功";
	}
	
}
